#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QWidget>
#include <QList>
#include "cabinet.h"
#include "cabinetconfig.h"
#include "userinfo.h"
#include "lockctrl.h"
#include "server.h"
#include <QHBoxLayout>
#include <QTimer>
#include <QDateTime>
#include <QThread>
#include "keyboad.h"
#include "ctrlreport.h"
#include "Temperature/tempmain.h"
//#include "Temperature/tempmanager.h"
#include "devicemanager.h"
#include "setting.h"
#include "http/httpserver.h"

namespace Ui {
class MainWidget;
}

class MainWidget : public QWidget
{
    Q_OBJECT

public:
    explicit MainWidget(QWidget *parent = 0);
    void globalTouch();
    ~MainWidget();

private slots:
    void recvCardReader(QString cardId);
    void recvScanData(QString scanData);
    void showSetting();
    void closeSetting();
    void selCaseChanged(QPoint);//柜格点击槽
    void ctrlRst(bool success);
    void keyBoadClicked(QString str);
    void cabinetTextsChanged(int col, QStringList texts);
    void sysTimeout();
    void recv_goods_fetch_rst(QString msg);
    void on_set_clicked();
    void on_mainPage_back_clicked();
    void on_cab_add_clicked();
    void on_cab_minus_clicked();
    void on_scr_col_valueChanged(int arg1);
    void on_set_scr_clicked(bool checked);
    void on_set_lock_clicked();
    void on_set_scr_toggled(bool checked);
    void on_lock_auto_clicked();
    void on_menu_user_clicked();
    void on_menu_layout_clicked();//布局配置界面切换
    void on_cardId_editingFinished();//用户配置界面刷卡验证槽
    void on_user_add_clicked();
    void on_user_del_clicked();
    void on_stack_panel_currentChanged(int arg1);
    void on_users_cellClicked(int row, int column);
    void on_user_clear_clicked();
    void on_lock_open_clicked();
    void on_lock_fresh_clicked();
    void on_lock_save_clicked();
    void on_cabinet_id_editingFinished();
    void on_spc_save_clicked();
    void on_scan_reader_returnPressed();
    void on_scan_push_clicked();
    void on_logout_clicked();
    void on_search_toggled(bool checked);
    void on_search_text_textChanged(const QString &arg1);
    void on_search_text_returnPressed();
    void on_depart_name_editingFinished();
    void on_server_address_editingFinished();
    void on_depart_id_editingFinished();
//    void on_test_clicked();
    void on_ctrl_address_editingFinished();

signals:
    void selUserChanged(int idx);
    void fetchGoodsReq(QString departId, QString userId, QString goodsId);

private:
    Ui::MainWidget *ui;
    QList<Cabinet*> listCabinet;
    QList<UserInfo*> listUser;
    Setting* win_setting;
    UserInfo* curUser;
    CabinetConfig* config;
    QThread thServer;
    QPoint selCase;
    QPoint spc;
    LockCtrl* locker;
    DeviceManager* devManager;
    QTimer* sysTimer;
    server* sev;
    HttpServer* httpServer;
    CtrlReport* ctrlReport;
    Keyboad* keyboad;
    QDateTime loginTime;
    QString optMsg;

    void initCabinets(QStringList layouts);
    void initLocker();
    UserInfo* checkInfo();
    void updateUserTable();
    void updateComDev();
    void updateTempMsg(QString msg);
    int userIndex(QString id, QList<UserInfo*>);
    int cardIndex(QString card, QList<UserInfo*>);
    void updateCabLayout(QHBoxLayout* lay, QList<Cabinet*> cabs);
    void selUser(int idx);
    void pushScan();
    void checkUser();
    void clearSearch();
};

#endif // MAINWIDGET_H
